


 // var baseURL = 'http://hbox1.wexiang.vip/';
  
  
  //正式 
   var baseURL = 'https://api.fzyaojia.top/';

uni.setStorageSync('upimg', baseURL);//邀请码
export function request(app) {
	app.config.globalProperties.http = (urls, data, method, baseurl,isload) => {
		uni.showLoading()
		var url
		if(baseurl){
			url = baseURL + urls
		}else{
			url = baseURL + urls
		}
		return new Promise(function(resolve, reject) {
			uni.request({
				url,
				header: {
					'Authorization': uni.getStorageSync("token") ? uni.getStorageSync("token") : ''
				},
				method: method ? method : 'GET',
				data: data ? data : {},
				success: (res) => {
					if(res.statusCode == 200){
						if (res.data.code === 0) {
							resolve(res.data);
						}else{
							uni.showToast({
								title: res.data.msg || res.data.message,
								icon: "none"
							})
							reject(res.data);
						}
					}else if (res.statusCode == 401) {
						 uni.removeStorageSync('token')
						uni.showToast({
							title: '登录已过期，请重新登录',
							icon: "none"
						})
						uni.reLaunch({
							url:"/pages/login"
						})
						
						reject(res)
					} else {
						reject(res)
						if (res.data.message) {
							uni.showToast({
								title: res.data.message,
								icon: "none"
							})
						} else {
							if(res.data.code !=11000){
								uni.showToast({
									title: res.data.message,
									icon: "none"
								})
							}
						}
					}
				},
				complete() {
				    uni.hideLoading()
				},
				fail: (res) => {
					reject(res)
					uni.showToast({
						title: "系统频繁，稍后重试",
						icon: "none"
					})
				}
			})
		})
	}
}